# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=libconfig
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.3
pkgrel=2
pkgdesc="C/C++ Configuration File Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/hyperrealm/libconfig"
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
options=('!emptydirs')
source=("https://github.com/hyperrealm/libconfig/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-mingw-fixes.patch")
sha256sums=('68757e37c567fd026330c8a8449aa5f9cac08a642f213f2687186b903bd7e94e'
            '67eb0e533f256ee6f9f6734868d96e2f4b5be9dd1b165765e862ad3a6ff0a006')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/001-mingw-fixes.patch"

  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  CFLAGS+=" -Wno-implicit-function-declaration" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --disable-examples \
    --enable-shared \
    --enable-static

  make lib
}

package() {
  cd "${srcdir}/build-${MSYSTEM}/lib"

  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
